<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>第&nbsp;10&nbsp;章.Web构建快速入门 - Web Application Quickstart</title>
<link xmlns:xslthl="http://xslthl.sf.net" type="text/css"
	rel="stylesheet" href="../css/base.css">
<link xmlns:xslthl="http://xslthl.sf.net" type="text/css"
	rel="stylesheet" href="../css/docs.css">
<link xmlns:xslthl="http://xslthl.sf.net" type="text/css"
	rel="stylesheet" href="../css/userguide.css">
<meta content="DocBook XSL Stylesheets V1.75.2" name="generator">
<link rel="home" href="../userguide.html" title="Gradle User Guide">
<link rel="up" href="../userguide.html" title="Gradle User Guide">
<link rel="prev" href="../tutorial_groovy_projects.html"
	title="第&nbsp;9.&nbsp;章:Groovy快速入门">
<link rel="next" href="../tutorial_gradle_command_line.html"
	title="第&nbsp;11.&nbsp;章:使用命令行">
</head>
<body>
	<div class="navheader">
		<div>
			<div class="navbar">
				<a xmlns:xslthl="http://xslthl.sf.net"
					href="../tutorial_groovy_projects.html"
					title="第&nbsp;9.&nbsp;章:Groovy快速入门">上一页</a><span>|</span><a
					xmlns:xslthl="http://xslthl.sf.net" href="../userguide.html"
					title="Gradle User Guide">返回目录</a><span>|</span><a
					xmlns:xslthl="http://xslthl.sf.net"
					href="../ch11/tutorial_gradle_command_line.html"
					title="第&nbsp;11.&nbsp;章:使用命令行">下一页</a>
			</div>
		</div>
	</div>
	<div class="chapter">
		<div class="titlepage">
			<div>
				<div>
			
					<h1 xmlns:xslthl="http://xslthl.sf.net">
						<a name="web_project_tutorial"></a>   第&nbsp;10&nbsp;章.Web构建快速入门 
					</h1>
					<h3 xmlns:xslthl="http://xslthl.sf.net">
                        <a name="web_project_tutorial"></a>Chapter&nbsp;10.&nbsp;Web
                        Application Quickstart
                    </h3>
				</div>
			</div>
		</div>
		<div class="note">
			<p>
			本章正在完善中<br>
			This chapter is a work in progress.</p>
		</div>
		<p>
		本章介绍了Gradle对Web工程的相关支持.Gradle为Web开发提供了两个主要插件,War plugin 和 Jetty plugin.
		其中War plugin继承自Java plugin,可以用来打war包.jetty plugin继承自War plugin作为工程部署的容器.<br>
		This chapter introduces some of the Gradle's support for web
			applications. Gradle provides two plugins for web application
			development: the War plugin and the Jetty plugin. The War plugin
			extends the Java plugin to build a WAR file for your project. The
			Jetty plugin extends the War plugin to allow you to deploy your web
			application to an embedded Jetty web container.</p>
		<div class="section">
			<div class="titlepage">
				<div>
					<div>
						<h2 class="title">
                            <a name="N10722"></a>10.1.&nbsp;打War包
                        </h2>
						<h4 class="title">
							<a name="N10722"></a>10.1.&nbsp;Building a WAR file
						</h4>
					</div>
				</div>
			</div>
			<p>
			需要打包War文件,需要在脚本中使用War plugin:<br>
			To build a WAR file, you apply the War plugin to your project:</p>
			<div class="example">
				<a name="webQuickstart"></a>
				<p class="title">
					<b>
					例&nbsp;10.1.&nbsp;War plugin<br>
					Example&nbsp;10.1.&nbsp;War plugin</b>
				</p>
				<div class="example-contents">
					<p>
						<code class="filename">build.gradle</code>
					</p>
					<pre class="programlisting">apply plugin: <span
							xmlns:xslthl="http://xslthl.sf.net" class="hl-string">'war'</span>
					</pre>
					<div class="exampleLocation">
						<p>
						<span class="emphasis"><em>备注:</em></span> 本示例代码可以在Gradle发行包中的
                            <code class="filename">samples/webApplication/quickstart</code>
                            路径下找到<br>
							<span class="emphasis"><em>Note:</em></span> The code for this
							example can be found at
							<code class="filename">samples/webApplication/quickstart</code>
							which is in both the binary and source distributions of Gradle.
						</p>
					</div>
				</div>
			</div>
			<br class="example-break">
			<p>
			    由于继承自Java插件,当你执行 <strong class="userinput"><code>gradle build</code></strong>时,将会编译、测试、打包你的工程.
			    Gradle会在 <code class="filename">src/main/webapp</code>下寻找Web工程文件.编译后的classes文件以及运行时依赖也都会被包含在War包中.<br>
				This also applies the Java plugin to your project. Running <strong
					class="userinput"><code>gradle build</code></strong> will compile,
				test and WAR your project. Gradle will look for the source files to
				include in the WAR file in
				<code class="filename">src/main/webapp</code>
				. Your compiled classes, and their runtime dependencies are also
				included in the WAR file.
			</p>
			<div class="tip">
				<h3 class="title">Groovy web构建</h3>
				<h5 class="title">Groovy web applications</h5>
				<p>
				在一个工程中你可以采用多个插件.比如你可以在web工程中同时使用War plugin和Groovy plugin.
				插件会将Gradle依赖添加到你的War包中.<br>
				You can combine multiple plugins in a single project, so you
					can use the War and Groovy plugins together to build a Groovy based
					web application. The appropriate groovy libraries will be added to
					the WAR file for you.</p>
			</div>
		</div>
		<div class="section">
			<div class="titlepage">
				<div>
					<div>
						<h2 class="title">
							<a name="N10747"></a>10.2.&nbsp;Web工程启动
						</h2>
						<h4 class="title">
                            <a name="N10747"></a>10.2.&nbsp;Running your web application
                        </h4>
					</div>
				</div>
			</div>
			<p>
			要启动Web工程,只需使用Jetty plugin即可:<br><br>
			To run your web application, you apply the Jetty plugin to
				your project:</p>
			<div class="example">
				<a name="webQuickstart"></a>
				<p class="title">
					<b>
					例&nbsp;10.2.&nbsp;采用Jetty plugin启动web工程<br>
					Example&nbsp;10.2.&nbsp;Running web application with Jetty
						plugin</b>
				</p>
				<div class="example-contents">
					<p>
						<code class="filename">build.gradle</code>
					</p>
					<pre class="programlisting">apply plugin: <span
							xmlns:xslthl="http://xslthl.sf.net" class="hl-string">'jetty'</span>
					</pre>
				</div>
			</div>
			<br class="example-break">
			<p>
			     由于Jetty plugin继承自War plugin.调用<strong class="userinput"><code>gradle jettyRun</code></strong> 将会把你的工程启动部署到jetty容器中.
			     调用<strong class="userinput"><code>gradle jettyRunWar</code></strong>会打包并启动部署到jetty容器中.<br>
				This also applies the War plugin to your project. Running <strong
					class="userinput"><code>gradle jettyRun</code></strong> will run
				your web application in an embedded Jetty web container. Running <strong
					class="userinput"><code>gradle jettyRunWar</code></strong> will
				build the WAR file, and then run it in an embedded web container.
			</p>
			<p>
			TODO:url,端口,以及源文件位置都可以在脚本中进行指定.<br>
			TODO: which url, configure port, uses source files in place
				and can edit your files and reload.</p>
		</div>
		<div class="section">
			<div class="titlepage">
				<div>
					<div>
						<h2 class="title">
							<a name="N10760"></a>10.3.&nbsp;本章汇总
						</h2>
						<h4 class="title">
                            <a name="N10760"></a>10.3.&nbsp;Summary
                        </h4>
					</div>
				</div>
			</div>
			<p>
			 了解更多关于War plugin和Jetty plugin的应用请参阅<a class="xref"
                    href="../war_plugin.html">第&nbsp;26&nbsp;章, <i>War Plugin</i></a>以及
                     <a class="xref" href="../jetty_plugin.html">第&nbsp;28&nbsp;章,
                    <i> Jetty Plugin</i>
                </a>. 你可以在发行包的<code class="filename">samples/webApplication</code>下找到更多示例.<br>
				You can find out more about the War plugin in <a class="xref"
					href="../war_plugin.html">Chapter&nbsp;26, <i>The War Plugin</i></a>
				and the Jetty plugin in <a class="xref" href="../jetty_plugin.html">Chapter&nbsp;28,
					<i>The Jetty Plugin</i>
				</a>. You can find more sample Java projects in the
				<code class="filename">samples/webApplication</code>
				directory in the Gradle distribution.
			</p>
		</div>
	</div>
	<div class="navfooter">
		<div>
			<div class="navbar">
				<a xmlns:xslthl="http://xslthl.sf.net"
					href="../tutorial_groovy_projects.html"
					title="第&nbsp;9.&nbsp;章:Groovy快速入门">上一页</a><span>|</span><a
					xmlns:xslthl="http://xslthl.sf.net" href="../userguide.html"
					title="Gradle User Guide">返回目录</a><span>|</span><a
					xmlns:xslthl="http://xslthl.sf.net"
					href="../ch11/tutorial_gradle_command_line.html"
					title="第&nbsp;11.&nbsp;章:使用命令行">下一页</a>
			</div>
		</div>
	</div>
</body>
</html>